package com.example.opencv_demo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.opencv_demo.activity.CameraViewActivity;
import com.example.opencv_demo.activity.DisplayModeActivity;
import com.example.opencv_demo.activity.Feature2dMainActivity;
import com.example.opencv_demo.activity.MainActivity;
import com.example.opencv_demo.activity.MainActivity2;
import com.example.opencv_demo.activity.MainActivity3;
import com.example.opencv_demo.adapter.MyAdapter;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;

import java.util.ArrayList;
import java.util.List;

public class IndexActivity extends AppCompatActivity {
    private List<MyAdapter.ActivityBean> mData = new ArrayList<>();
    private RecyclerView recyclerView;
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        recyclerView = findViewById(R.id.rv_index);
        myAdapter = new MyAdapter(mData, this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(myAdapter);
        initData();
        myAdapter.notifyDataSetChanged();
    }

    private void initData() {
        mData.add(new MyAdapter.ActivityBean("mat图片操作", MainActivity.class));
        mData.add(new MyAdapter.ActivityBean("图像处理", MainActivity2.class));
        mData.add(new MyAdapter.ActivityBean("基本特征检测", MainActivity3.class));
        mData.add(new MyAdapter.ActivityBean("特征检测和匹配", Feature2dMainActivity.class));
        mData.add(new MyAdapter.ActivityBean("相机使用", CameraViewActivity.class));
        mData.add(new MyAdapter.ActivityBean("相机使用2", DisplayModeActivity.class));

    }

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
                    Log.i("OpenCV", "OpenCV loaded successfully");
                }
                break;
                default: {
                    super.onManagerConnected(status);
                }
                break;
            }
        }
    };

    @Override
    protected void onResume() {
        super.onResume();
        if (!OpenCVLoader.initDebug()) {
            Log.d("TAG", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_2_0, this, mLoaderCallback);
        } else {
            Log.d("TAG", "OpenCV library found inside package. Using it!");
            mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        }
    }


}